//
//  QSWorlStationRemarkCell.m
//  DigitalEconomy_iOS
//
//  Created by Ding on 2020/5/20.
//  Copyright © 2020 DingC. All rights reserved.
//

#import "QSWorlStationRemarkCell.h"

@implementation QSWorlStationRemarkCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self configSubView];
    }
    return self;
}
- (void)configSubView{
    [self addSubview:self.remarkTextView];
    
    self.backgroundColor = [UIColor clearColor];
    self.contentView.layer.cornerRadius = 8;
    self.contentView.layer.masksToBounds = YES;
    self.contentView.backgroundColor = [UIColor QSColorWhiteFFFFFF];
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self).offset(kRealValue(10));
        make.trailing.equalTo(self).offset(- kRealValue(10));
        make.top.equalTo(self.mas_top).offset(kRealValue(0));
        make.bottom.equalTo(self.mas_bottom).offset(- kRealValue(10));
    }];
    [_remarkTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(self.contentView);
    }];
}
- (DcTextView *)remarkTextView{
    if (!_remarkTextView) {
        _remarkTextView = [[DcTextView alloc]init];
        _remarkTextView.placeholder = @"请填写完成备注...";
        _remarkTextView.placeLab.textAlignment = NSTextAlignmentLeft;
        _remarkTextView.font = [UIFont QSFontOfSize14];
        _remarkTextView.backgroundColor = [UIColor clearColor];
        _remarkTextView.delegate = self;
    }
    return _remarkTextView;
}

//收起键盘回调
- (void)textViewDidEndEditing:(UITextView *)textView{
    if (self.didInputFinish) {
        self.didInputFinish(textView.text);
    }
    
}

- (BOOL)textView:(UITextView *)textView shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    //禁止输入空格
    NSString *tem = [[string componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]componentsJoinedByString:@""];
    if (![string isEqualToString:tem]) {
        return NO;
    }
    return YES;
}
//换行变搜索
-(BOOL)textViewShouldReturn:(UITextView *)textView
{
    NSLog(@"7");// 点击键盘的‘换行’会调用
    [textView resignFirstResponder];
    return YES;
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if (text.length == 0) return YES;//允许删除。
    if (textView.text.length >= 200) {
        return NO;
    }else{
        return YES;
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
